﻿/**
 * $HeadURL: https://smartcollector.googlecode.com/svn/branches/Srcs/SmartCollector.GUI/AddSite.cs $
 * $Author: chithanh12 $
 * $Date: 2011-04-09 00:11:43 +0700 (Sat, 09 Apr 2011) $
 * $Rev: 60 $
 **/

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SmartCollector.Domain.Repository;
using SmartCollector.Domain.Entity;
using HtmlParser;

namespace SmartCollector.GUI
{
    public partial class AddSite : Form
    {
        private SiteRepository m_siteRepository;
        public AddSite()
        {
            InitializeComponent();
        }
        public AddSite(SiteRepository siteRepository):this()
        {
            m_siteRepository = siteRepository;
        }

        private void OnSave(object sender, EventArgs e)
        {
            if (m_txtSiteName.Text.Trim().Length == 0 || !m_txtSiteLink.Text.Trim().IsInternetLink())
            {
                MessageBox.Show("Please input valid data!\n The link should be http://.....");
                return;
            }
            m_siteRepository.AddNewSites(
               new tbl_ReferenceSite
               {
                   SiteName = m_txtSiteName.Text,
                   Url = m_txtSiteLink.Text
               });
            m_siteRepository.SubmitChanges();
            this.DialogResult = System.Windows.Forms.DialogResult.OK;
            Close();
        }

        protected override void OnClosed(EventArgs e)
        {
            m_siteRepository = null;
            base.OnClosed(e);
        }

        private void OnCancel(object sender, EventArgs e)
        {
            this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            Close();
        }
        
    }
}
